//维修年计划
import React, { Component } from 'react';
import { Table, Button, Form, Card ,Tabs } from 'antd';
import '@/assets/css/settings';
import BasicForm from "../../components_yyr/common/basicForm";
import BasicDrawer from "../../components_yyr/common/basicDrawer";
import Paging from "../../components_yyr/commponent/Paging";
const { TabPane } = Tabs;
class App extends Component {
	state = {
		loading: false, //加载中...
		dataSource: [], //数据源
		drawerVisible: false,//新增修改抽屉的显示与隐藏
		chooseData: {},
		drawerTitle: '',
		total:0,
		formValues:{},
		cityData:[],
		mainFactoryList:[]
	};
	componentDidMount() {
		this.fetch({
			pageNum: 1,
			pageSize: 10
		});
		// this.getInfo();
	}
	//初始化加载数据
	fetch = (data) => {
		// this.setState({ loading: true })
		// this.post('/airCargo/pageList',{data}).then(res => {
		// 	this.setState({
		// 		loading: false,
		// 		dataSource: res.data.data,
		// 		total:res.data.total,
		// 		formValues:data
		// 	});
		// })
	}
	getInfo=()=>{
		this.post('/carrierPrice/mainFactoryList').then(res => this.setState({	mainFactoryList: res.data}))//主机厂
	}

	//表单查询
	filterSubmit = (values) => {
		values.pageNum = this.state.formValues.pageNum;
		values.pageSize = this.state.formValues.pageSize;
		this.fetch(values);
	};

	handleConfirm = (value, api,chooseData) => {
		if(api===1){
			this.get(`/airCargo/delAirCargo?id=${chooseData.id}`).then(res=>{
				this.success();
				this.fetch({...this.state.formValues});
			})
		}
		
	}

	formList = () => {
		const formList = [
			{				type: "TIMEFRAME", label: "计划时间", field: "factoryName",},
			{				type: "INPUT", label: "设备信息", field: "route" 	  },
		]
		return formList;
	};
	drawerFormList = data => {
		const {mainFactoryList}=this.state;
    const drawerFormList = [
		{
			type: "SELECT",
			label: "主机厂",
			field: "uniqueAddress",
			initialValue: data.uniqueAddress,
			list:mainFactoryList,
			valueField:'uniqueAddress',
			name:'mainFactoryName',
			required:true
		},
		{
			type: "INPUT",
			label: "航线",
			field: "route",
			initialValue: data.route,
			required:true
		},
		{ type: "INPUTNUMBER",label: "港到港最低价",field: "harborMinimumPrice",initialValue:data.harborMinimumPrice,required:true},
		{ type: "INPUTNUMBER",label: "港到港100KG以下",field: "harborOneHundredPrice",initialValue:data.harborOneHundredPrice,required:true},
		{ type: "INPUTNUMBER",label: "港到港100KG-299kg",field: "harborTwoHundredPrice",initialValue:data.harborTwoHundredPrice,required:true},
		{ type: "INPUTNUMBER",label: "港到港300KG-999kg",field: "harborNineHundredPrice",initialValue:data.harborNineHundredPrice,required:true},
		{ type: "INPUTNUMBER",label: "港到港1T以上",field: "harborOneTonPrice",initialValue:data.harborOneTonPrice,required:true},
		{ type: "INPUTNUMBER",label: "门到门最低价",field: "doorMinimumPrice",initialValue:data.doorMinimumPrice,required:true},
		{ type: "INPUTNUMBER",label: "门到门100KG以下",field: "doorOneHundredPrice",initialValue:data.doorOneHundredPrice,required:true},
		{ type: "INPUTNUMBER",label: "门到门100KG-299kg",field: "doorTwoHundredPrice",initialValue:data.doorTwoHundredPrice,required:true},
		{ type: "INPUTNUMBER",label: "门到门300KG-999kg",field: "doorNineHundredPrice",initialValue:data.doorNineHundredPrice,required:true},
		{ type: "INPUTNUMBER",label: "门到门1T以上",field: "doorOneTonPrice",initialValue:data.doorOneTonPrice,required:true},
		{ type: "DATE",label: "门到门到达时间",field: "date_doorArrivalTime",initialValue:this.getDateByString(data.doorArrivalTime,'YYYY-MM-DD'),required:true},
		{ type: "INPUTNUMBER",label: "里程",field: "mileage",initialValue:data.mileage,required:true},
		{ type: "INPUTNUMBER",label: "专车费用",field: "specialBusFee",initialValue:data.specialBusFee,required:true},
		{ type: "DATE",label: "配送时间",field: "date_deliveryTime",initialValue:this.getDateByString(data.deliveryTime,'YYYY-MM-DD'),required:true},
		{ type: "TEXTAREA",label: "备注",field: "remarks",initialValue:data.remarks}
    ];
    return drawerFormList;
	};
	
	  // 提交modal
		handleSubmit = data => {
			const id = this.state.chooseData && this.state.chooseData.id;
			if (id) {
				data=Object.assign({}, data,{id:id });
				data.updateId=localStorage.getItem('userId');
			}else{
				data.createId=localStorage.getItem('userId');
			}
			this.post('/airCargo/addAirCargo',{data}).then(res=>{
				this.success();
				this.fetch({...this.state.formValues});
				this.onClose();
			})
			
		};

			// 打开modal，判断是修改还是新增 0新增 1修改
		handleModal = (type,data ) => {
			if (type) {
				this.setState({
					drawerTitle: "修改",
					drawerVisible: true,
					chooseData:data
				});
			} else {
					this.setState({
					drawerTitle: "新增",
					drawerVisible: true,
				});
			}
		};


		onClose=()=>{
			this.setState({
				drawerVisible: false,
				chooseData: {}
			});
			this.modalRef.props.form.resetFields();
		}


	render() {
		const columns = [
			{
				title: '设备编号',
				width:150,
				dataIndex: 'factoryName',
			},
			{
				title: '设备名称',
				width:100,
				dataIndex: 'route',
			},
			{
				title: '维修人员',
				width:150,
				dataIndex: 'harborMinimumPrice',
			},
			
			{
				title: '计划(人*时*天)',
				width:150,
				dataIndex: 'doorOneHundredPrice',
			},
			{
				title: '总计划工时',
				width:150,
				dataIndex: 'doorTwoHundredPrice',
			},
			{
				title: '外协工时',
				width:150,
				dataIndex: 'doorNineHundredPrice',
			},
			{
				title: '备注',
                width:100,
				dataIndex: 'remarks',
			},
            {
				title: '年计划',
                width:100,
				dataIndex: 'yearPlan',
			},
			{
				title: '操作',
				width:150,
				render: (text, record) => {
					return	<span>
						{/* <a href onClick={()=>this.handleModal(1,record)}>详细</a>
						<Divider type="vertical" /> */}
						<a href onClick={()=>this.handleModal(1,record)}>修改</a>
						{/* <Divider type="vertical" />
						<BasicConfirm title='确认删除?'api={1} button={false} buttonName='删除' data={record}  handleConfirm={this.handleConfirm}/> */}
					</span>
				}
			}
		];

		const {chooseData,drawerVisible,drawerTitle,dataSource,loading,total,formValues}=this.state;
	
		const drawerProps={
			onRef:(ref)=>this.modalRef=ref,visible:drawerVisible,width:700,drawerFormList:this.drawerFormList(chooseData),
			submit:this.handleSubmit,onClose:this.onClose,title:drawerTitle
		}

		return (
			<div className="shadow-radius">
				<Card><BasicForm formList={this.formList()} filterSubmit={this.filterSubmit} labelSpan={8} wrapperSpan={12} onRef={(ref) => this.child = ref} /></Card>
				
                <Tabs tabBarExtraContent={
                    <div className="buttonList">
					<Button icon="plus" onClick={()=>this.handleModal(0,{})} type="primary"> 添加计划</Button>
					{/* <Button icon="edit" onClick={()=>this.handleModal(0,{})} type="primary"> 调整计划执行时间</Button>
					<Button icon="form" onClick={()=>this.handleModal(0,{})} type="primary"> 执行计划</Button>
					<Button icon="apartment" onClick={()=>this.handleModal(0,{})} type="primary"> 派工</Button> */}
					<Button icon="delete" onClick={()=>this.handleModal(0,{})} type="primary"> 删除</Button>  
					{/* <FileDown fileName='设备台账模板' buttonName='模板下载' apiPath='/airCargo/carrierPriceExcel'/> */}
					{/* <FileDown fileName='维修计划清单' buttonName='导出' method='post' apiPath='/airCargo/exportCarrierPriceDataExcel' data={formValues}/> */}
					{/* <FileUpload buttonName='导入' apiPath='/airCargo/carrierPriceExcel' load={true} fetch={()=>this.fetch({...formValues})}/> */}
				</div>
                }>
                    <TabPane tab='维修年计划' key='1'>
                        <Table columns={columns} rowKey={(record, index) => index} dataSource={dataSource} pagination={false}	loading={loading} scroll={{y:500,x:1300}} 	/>
                        <Paging total={total} formValues={formValues} fetch={(pager)=>this.fetch(pager)}/>
                    </TabPane>
                </Tabs>
				

				<BasicDrawer	{...drawerProps} />

			</div>
		);
	}
}
export default Form.create()(App);